package com.base.caselib.presenter;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.arvin.imagepicker.Util;
import com.arvin.imagepicker.bean.ImageItem;
import com.arvin.imagepicker.widget.ImagePickView;
import com.base.caselib.bean.CaseAb;
import com.base.caselib.bean.CaseBean;
import com.base.caselib.bean.CaseDetailBean;
import com.base.caselib.bean.CaseSaveBean;
import com.base.caselib.bean.CaseType;
import com.base.caselib.bean.CheckBoxBean;
import com.base.caselib.bean.UpateMainCaseInfoBean;
import com.base.caselib.bean.UpdateChildValueInfoBean;
import com.base.caselib.view.CaseEditView;
import com.base.caselib.widget.CheckBoxCustom;
import com.base.caselib.widget.DateCustom;
import com.base.caselib.widget.EditNumCustom;
import com.base.caselib.widget.EditTextCustom;
import com.base.caselib.widget.SingleCheckCustom;
import com.base.caselib.widget.SpinnerCustom;
import com.base.commonlib.base.BaseApp;
import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2019/10/12.
 */

public class CaseEditPresenter extends BasePresenter<CaseEditView>{
    public String ID = "ylp9W4bF9ykafcByq8R";
    public int isSimple = 2;
    private static final int ERROR_MESS = 1;
    private static final int SUCCESS_MESS = 2;
    public CaseDetailBean mCaseBean = null;
    public String mTpeId = "";//逐渐类型ID
    public String mAnJianType = "";
    public String mNoticeId = "";
    private CaseDetailBean mDetailBean;
    private boolean isSave = true;//是否保存 （默认保存）

    private CaseSaveBean mCaseSaveBean = new CaseSaveBean();
    private UpateMainCaseInfoBean mUpdateMainCaseInfo = new UpateMainCaseInfoBean();
    private List<UpdateChildValueInfoBean> mUpdateChildCaseInfoList = new ArrayList<>();
    private CaseAb mCaseAb = new CaseAb();//案情摘要
    public CaseEditPresenter(CaseEditView view, Activity activity) {
        super(view, activity);
    }

    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case ERROR_MESS:
                    mView.hidePb_mes();
                    mView.showMes("模块为找到索引");
                    break;
                case SUCCESS_MESS:
                    mCaseSaveBean.setMainDatas(mMasterCommBean);
                    mCaseSaveBean.setSonDatas(mChildCommBean);
                    mView.hidePb_mes();
                    if (TextUtils.isEmpty(mTpeId)){
                        mView.showMes("请选择案件类型");
                        return;
                    }
                    updateMainValue();
                    break;
            }
        }
    };
    private void updateMainValue(){

        mUpdateMainCaseInfo.setMainDatas(mMasterCommBean);
        CaseSaveBean.CommenBean mComBean = new CaseSaveBean.CommenBean();
        mComBean.setFieldSave("case_number");
        mComBean.setValue(mAnJianType);
        mUpdateMainCaseInfo.getMainDatas().add(mComBean);
        mComBean = new CaseSaveBean.CommenBean();
        mComBean.setFieldSave("notification_number");
        mComBean.setValue(mNoticeId);
        mUpdateMainCaseInfo.getMainDatas().add(mComBean);

        mComBean = new CaseSaveBean.CommenBean();
        mComBean.setFieldSave("case_summary");
        mCaseAb.setCaseCame("巡查发现");
        mCaseAb.setCasePerson(mUser.getUserName()+","+mCurrentPartner.getUserName());
        mComBean.setValue(mCaseAb.getCaseTime()+mCaseAb.getCasePerson()+"在"+mCaseAb.getCaseAddress()+mCaseAb.getCaseCame()+mCaseAb.getCaseName()+mCaseAb.getCaseLow());
        mUpdateMainCaseInfo.getMainDatas().add(mComBean);
        mUpdateMainCaseInfo.setFormId(mCaseBean.getId());
        mUpdateMainCaseInfo.setFormMainValue(mCaseBean.getFormMainValue());

        mComBean = new CaseSaveBean.CommenBean();
        mComBean.setFieldSave("law_enforcing_department_name2");
        mComBean.setValue(mUser.getDeptId());
        mUpdateMainCaseInfo.getMainDatas().add(mComBean);

        mComBean = new CaseSaveBean.CommenBean();
        mComBean.setFieldSave("law_enforcing_member_name1");
        mComBean.setValue(mUser.getUserId());
        mUpdateMainCaseInfo.getMainDatas().add(mComBean);

        mComBean = new CaseSaveBean.CommenBean();
        mComBean.setFieldSave("law_enforcing_member_name2");
        mComBean.setValue(mCurrentPartner.getId());
        mUpdateMainCaseInfo.getMainDatas().add(mComBean);

        mComBean = new CaseSaveBean.CommenBean();
        mComBean.setFieldSave("law_enforcing_department_name");
        mComBean.setValue(mUser.getCompanyId());
        mUpdateMainCaseInfo.getMainDatas().add(mComBean);
        mUpdateMainCaseInfo.setId(mView.getCaseid());


        //初始化控件
        mView.showPb_mes("正在提交数据");
        Disposable disposable = RealNetWorkUtil.postContent()
                .method("api-customerform/baseFunction/update1")
                .content(mUpdateMainCaseInfo)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        mView.showMes("保存失败");
                    }

                    @Override
                    public void onNext(String objects) {
                        mView.hidePb_mes();
                        updateChildValue();
                    }
                });
        mCompositeDisposable.add(disposable);
    }
    @Override
    public void start() {
        super.start();
    }
    public void getInfoCasedetail(String cformId,String id){
        Map<String,String> parmes = new HashMap<>();
        parmes.put("id",id);
        parmes.put("cformId",cformId);
        //初始化控件
        mView.showPb_mes("正在渲染界面");
        Disposable disposable = RealNetWorkUtil.postContent()
                .method("api-customerform/baseFunction/goToInfo")
                .content(parmes)
                .build().enqueue(CaseDetailBean.class, new CallBackImpl<CaseDetailBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        if (!TextUtils.isEmpty(msg)) {
                            mView.showMes(msg);
                        }

                    }
                    @Override
                    public void onNext(CaseDetailBean version) {
                        mView.hidePb_mes();
                        mView.returnCaseBean(version);
                    }
                });
        mCompositeDisposable.add(disposable);
    }
    //更新案件
    public void updataCase(List<LinearLayout> linearLayouts){
        isSave = false;
        if (mCaseBean == null){
            mView.showMes("请先渲染页面");
            return;
        }
        mCaseSaveBean.setFormId(mCaseBean.getId());
        mCaseSaveBean.setFormMainValue(mCaseBean.getFormMainValue());
        mChildCommBean.clear();
        mMasterCommBean.clear();
        mView.showPb_mes("正在构建实体");
        //遍历主表拼接字段
        if (mCaseBean != null){
            structure(linearLayouts);
        }else {
            mView.showMes("请先渲染页面");
        }
    }

    public void getFieldValue(Map<String,String> map, final SpinnerCustom custom, final boolean isDefault){
        //初始化控件
        mView.showPb_mes("正在请求数据");
        Disposable disposable = RealNetWorkUtil.postContent()
                .method("api-customerform/baseForm/dropValue")
                .content(map)
                .build().enqueueForArray(CheckBoxBean.class, new CallBackImpl<List<CheckBoxBean>>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        mView.showMes(msg);
                    }

                    @Override
                    public void onNext(List<CheckBoxBean> objects) {
                        mView.hidePb_mes();
                        if (objects.size()==0){
                            if (!isDefault){
                                mView.showMes("无数据");
                            }
                        }else {
                            if (isDefault){
                                if (objects.size()>0) {
                                    custom.setData(objects);
                                    if (custom.getName().equals("执法部门：")){
                                        for (CheckBoxBean bean : objects){
                                            if (bean.getDropLabel().equals(mUser.getCompanyName())){
                                                custom.setDefault(bean);
                                            }
                                        }
                                    }else {
                                        custom.setDefault(objects.get(0));
                                    }
                                }
                            }else {
                                custom.setData(objects);
                                custom.show(false);
                            }
                        }
                    }
                });
        mCompositeDisposable.add(disposable);
    }
    public void getFieldValue(Map<String,String> map, final SpinnerCustom custom, final boolean isDefault, final String key){
        //初始化控件
        mView.showPb_mes("正在请求数据");
        Disposable disposable = RealNetWorkUtil.postContent()
                .method("api-customerform/baseForm/dropValue")
                .content(map)
                .build().enqueueForArray(CheckBoxBean.class, new CallBackImpl<List<CheckBoxBean>>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        mView.showMes(msg);
                    }

                    @Override
                    public void onNext(List<CheckBoxBean> objects) {
                        mView.hidePb_mes();
                        if (objects.size()==0){
                            if (!isDefault){
                                mView.showMes("无数据");
                            }
                        }else {
                            if (isDefault){
                                if (objects.size()>0) {
                                    custom.setData(objects);
                                        for (CheckBoxBean bean : objects){
                                            if (bean.getDropValue().equals(key)){
                                                custom.setDefault(bean);
                                            }
                                        }
                                }
                            }else {
                                custom.setData(objects);
                                custom.show(false);
                            }
                        }
                    }
                });
        mCompositeDisposable.add(disposable);
    }

    public void setmCaseBean(CaseDetailBean bean){
        this.mCaseBean = bean;
    }

    List<CaseSaveBean.CommenBeanToUp> list = null;

    //新增保存案件
    public void save(List<LinearLayout> linearLayouts){
        isSave = true;
        if (mCaseBean == null){
            mView.showMes("请先渲染页面");
            return;
        }
        mCaseSaveBean.setFormId(mCaseBean.getId());
        mCaseSaveBean.setFormMainValue(mCaseBean.getFormMainValue());
        mChildCommBean.clear();
        mMasterCommBean.clear();
        mView.showPb_mes("正在构建实体");
        //遍历主表拼接字段
        if (mCaseBean != null){
            structure(linearLayouts);
        }else {
            mView.showMes("请先渲染页面");
        }


    }
    //构建主表实体/构建字表实体
    private void structure(final List<LinearLayout> linearLayouts){
        //开启线程构建实体
        new Thread(new Runnable() {
            @Override
            public void run() {
                //需要在子线程中处理的逻辑

                for (LinearLayout layout : linearLayouts){
                    if (layout.getTag() != null){
                        for (CaseDetailBean.ModulesBean modulesBean : mCaseBean.getModules()){
                            String type = modulesBean.getModuleIndex()+"";
                            if (type.equals(layout.getTag().toString())){
                                //找到当前控件实体
                                if (modulesBean.getModuleType() ==1){//主表
                                    saveDate(layout,modulesBean,true,null);
                                }else if (modulesBean.getModuleType() ==2){//字表
                                    List<List<CaseSaveBean.CommenBeanToUp>> mCommBeanUp = new ArrayList<>();
                                    List<CaseSaveBean.CommenBeanToUp> list = new ArrayList<>();
                                    saveDate(layout,modulesBean,false,list);
                                    if (list != null&&list.size()>0){
                                        if (mChildCommBean.containsKey(modulesBean.getChildName())){
                                            for (Map.Entry<String, List<List<CaseSaveBean.CommenBeanToUp>>> entry : mChildCommBean.entrySet()) {
                                                if (entry.getKey().equals(modulesBean.getChildName())){
                                                    mCommBeanUp.addAll(entry.getValue());
                                                }
                                            }
                                            String fileSave = "";
                                            List<CaseSaveBean.CommenBeanToUp> ups = new ArrayList<>();
                                            for (CaseSaveBean.CommenBeanToUp commenBeanToUp : list){
                                                if (commenBeanToUp.getFieldSave().equals(fileSave)){
                                                    List<CaseSaveBean.CommenBeanToUp> list1 = new ArrayList<>();
                                                    list1.add(commenBeanToUp);
                                                    mCommBeanUp.add(list1);
                                                    mChildCommBean.put(modulesBean.getChildName(),mCommBeanUp);
                                                }else {
                                                    ups.add(commenBeanToUp);
                                                }
                                                fileSave = commenBeanToUp.getFieldSave();
                                            }
                                            mCommBeanUp.add(ups);
                                            mChildCommBean.remove(modulesBean.getChildName());
                                            mChildCommBean.put(modulesBean.getChildName(),mCommBeanUp);
                                        }else {
                                            String fileSave = "";
                                            List<CaseSaveBean.CommenBeanToUp> ups = new ArrayList<>();
                                            for (CaseSaveBean.CommenBeanToUp commenBeanToUp : list){
                                                if (commenBeanToUp.getFieldSave().equals(fileSave)){
                                                    List<CaseSaveBean.CommenBeanToUp> list1 = new ArrayList<>();
                                                    for (CaseSaveBean.CommenBeanToUp com : list){
                                                        if (!com.getFieldSave().equals(commenBeanToUp.getFieldSave())){
                                                            list1.add(com);
                                                        }
                                                    }
                                                    list1.add(commenBeanToUp);
                                                    mCommBeanUp.add(list1);
                                                }else {
                                                    ups.add(commenBeanToUp);
                                                }
                                                fileSave = commenBeanToUp.getFieldSave();
                                            }
                                            mCommBeanUp.add(ups);
                                            mChildCommBean.put(modulesBean.getChildName(),mCommBeanUp);
                                        }
                                    }

                                }
                            }
                        }
                    }else {
                        mHandler.sendEmptyMessage(ERROR_MESS);
                        return;
                    }
                }
                mHandler.sendEmptyMessage(SUCCESS_MESS);
            }
        }).start();
    }


    private Map<String,List<List<CaseSaveBean.CommenBeanToUp>>> mChildCommBean = new HashMap<>();
    List<CaseSaveBean.CommenBean> mMasterCommBean = new ArrayList<>();
    private void saveDate(LinearLayout views,CaseDetailBean.ModulesBean bean,boolean isMarstr,List<CaseSaveBean.CommenBeanToUp> list){
        CaseSaveBean.CommenBean commenBean = null;
        CaseSaveBean.CommenBeanToUp commenBeanUp = null;
        List<View> childsViews = getAllChildViews(views);
        for (View view : childsViews){
            if (view instanceof EditTextCustom) {
                if (isMarstr){
                    EditTextCustom custom = (EditTextCustom) view;
                    if(!TextUtils.isEmpty(custom.getmEtText())){
                        BaseApp.setHistoryText(mUser.getUserId(),custom.getmEtText());
                    }
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //主表
                            commenBean = new CaseSaveBean.CommenBean();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmEtText())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBean.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){

                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBean.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBean.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBean.setValue(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                                }
                            }else {
                                commenBean.setValue(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                            }
                            if (rowsBean.getRowLabel().equals("案发地点：")){
                                mCaseAb.setCaseAddress(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                            }
                            if (rowsBean.getRowLabel().contains("当事人")){
                                if (TextUtils.isEmpty(custom.getmEtText())){

                                }else {
                                    mCaseAb.setCaseName(TextUtils.isEmpty(custom.getmEtText()) ? null : custom.getmEtText());
                                }
                            }
                            commenBean.setConType(rowsBean.getConType());
                            commenBean.setFieldSave(rowsBean.getFieldSave());
                            commenBean.setValidate(rowsBean.getValidate());
                            commenBean.setRowLabel(rowsBean.getRowLabel());

                            mMasterCommBean.add(commenBean);
                        }
                    }
                }else {
                    EditTextCustom custom = (EditTextCustom) view;
                    if(!TextUtils.isEmpty(custom.getmEtText())){
                        BaseApp.setHistoryText(mUser.getUserId(),custom.getmEtText());
                    }
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //子表
                            commenBeanUp = new CaseSaveBean.CommenBeanToUp();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmEtText())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBeanUp.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){

                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBeanUp.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBeanUp.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBeanUp.setValue(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                                }
                            }else {
                                commenBeanUp.setValue(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                            }
                            if (rowsBean.getRowLabel().equals("案发地点：")){
                                mCaseAb.setCaseAddress(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                            }
                            if (rowsBean.getRowLabel().contains("当事人")){
                                if (TextUtils.isEmpty(custom.getmEtText())){

                                }else {
                                    mCaseAb.setCaseName(TextUtils.isEmpty(custom.getmEtText()) ? null : custom.getmEtText());
                                }
                            }
                            commenBeanUp.setConType(rowsBean.getConType());
                            commenBeanUp.setFieldSave(rowsBean.getFieldSave());
                            childPutBean(bean.getChildName(),commenBeanUp,list);
                        }
                    }
                }

            }else if (view instanceof EditNumCustom){
                if (isMarstr){
                    EditNumCustom custom = (EditNumCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //主表
                            commenBean = new CaseSaveBean.CommenBean();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmEtText())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBean.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){


                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBean.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBean.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBean.setValue(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                                }
                            }else {
                                commenBean.setValue(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                            }
                            commenBean.setConType(rowsBean.getConType());
                            commenBean.setFieldSave(rowsBean.getFieldSave());
                            commenBean.setValidate(rowsBean.getValidate());
                            commenBean.setRowLabel(rowsBean.getRowLabel());
                            mMasterCommBean.add(commenBean);
                        }
                    }
                }else {
                    EditNumCustom custom = (EditNumCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //子表
                            commenBeanUp = new CaseSaveBean.CommenBeanToUp();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmEtText())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBeanUp.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){

                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBeanUp.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBeanUp.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBeanUp.setValue(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                                }
                            }else {
                                commenBeanUp.setValue(TextUtils.isEmpty(custom.getmEtText())?null:custom.getmEtText());
                            }
                            commenBeanUp.setConType(rowsBean.getConType());
                            commenBeanUp.setFieldSave(rowsBean.getFieldSave());
                            childPutBean(bean.getChildName(),commenBeanUp,list);
                        }
                    }
                }

            }else if (view instanceof DateCustom){
                if (isMarstr){
                    DateCustom custom = (DateCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //主表
                            commenBean = new CaseSaveBean.CommenBean();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmTvDate())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBean.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){


                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBean.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBean.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {

                                    commenBean.setValue(TextUtils.isEmpty(custom.getmTvDate())?null:custom.getmTvDate());
                                }
                            }else {
                                commenBean.setValue(TextUtils.isEmpty(custom.getmTvDate())?null:custom.getmTvDate());
                            }
                            if (rowsBean.getRowLabel().equals("案发时间：")){
                                mCaseAb.setCaseTime(TextUtils.isEmpty(custom.getmTvDate())?null:custom.getmTvDate());
                            }
                            commenBean.setConType(rowsBean.getConType());
                            commenBean.setFieldSave(rowsBean.getFieldSave());
                            commenBean.setValidate(rowsBean.getValidate());
                            commenBean.setRowLabel(rowsBean.getRowLabel());
                            commenBean.setValue(TextUtils.isEmpty(custom.getmTvDate())?null:custom.getmTvDate());
                            mMasterCommBean.add(commenBean);
                        }
                    }
                }else {
                    DateCustom custom = (DateCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //子表
                            commenBeanUp = new CaseSaveBean.CommenBeanToUp();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmTvDate())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBeanUp.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){


                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBeanUp.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBeanUp.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBeanUp.setValue(TextUtils.isEmpty(custom.getmTvDate())?null:custom.getmTvDate());
                                }
                            }else {
                                commenBeanUp.setValue(TextUtils.isEmpty(custom.getmTvDate())?null:custom.getmTvDate());
                            }
                            if (rowsBean.getRowLabel().equals("案发时间：")){
                                mCaseAb.setCaseTime(TextUtils.isEmpty(custom.getmTvDate())?null:custom.getmTvDate());
                            }
                            commenBeanUp.setConType(rowsBean.getConType());
                            commenBeanUp.setFieldSave(rowsBean.getFieldSave());
                            childPutBean(bean.getChildName(),commenBeanUp,list);
                        }
                    }
                }

            }else if (view instanceof SpinnerCustom){
                if (isMarstr){
                    SpinnerCustom custom = (SpinnerCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){

                            if (rowsBean.getRowLabel().equals("案件类型：")){
                                mTpeId = custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropValue();
                            }
                            //主表
                            commenBean = new CaseSaveBean.CommenBean();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmCurrentBoxBean().getDropValue())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        if (rowsBean.getFixValue()!=null) {
                                            commenBean.setValue(rowsBean.getFixValue());
                                        }
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){

                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBean.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBean.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBean.setValue(custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropValue());
                                }
                            }else {
                                commenBean.setValue(custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropValue());
                            }
                            if (rowsBean.getRowLabel().equals("违法行为：")){
                                mCaseAb.setCaseLow(custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropLabel());
                            }
                            commenBean.setConType(rowsBean.getConType());
                            commenBean.setFieldSave(rowsBean.getFieldSave());
                            commenBean.setValidate(rowsBean.getValidate());
                            commenBean.setRowLabel(rowsBean.getRowLabel());

                            mMasterCommBean.add(commenBean);
                        }
                    }
                }else {
                    SpinnerCustom custom = (SpinnerCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //子表
                            commenBeanUp = new CaseSaveBean.CommenBeanToUp();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmCurrentBoxBean().getDropValue())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBeanUp.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){


                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBeanUp.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBeanUp.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBeanUp.setValue(custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropValue());
                                }
                            }else {
                                commenBeanUp.setValue(custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropValue());
                            }
                            commenBeanUp.setConType(rowsBean.getConType());
                            commenBeanUp.setFieldSave(rowsBean.getFieldSave());
                            childPutBean(bean.getChildName(),commenBeanUp,list);
                        }
                    }
                }

            }else if (view instanceof SingleCheckCustom){
                if (isMarstr){
                    SingleCheckCustom custom = (SingleCheckCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //主表
                            commenBean = new CaseSaveBean.CommenBean();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (custom.getmCurrentBoxBean() != null){
                                    if (custom.getmCurrentBoxBean().getDropValue() != null && TextUtils.isEmpty(custom.getmCurrentBoxBean().getDropValue())){
                                        if (rowsBean.getDefaultValue().equals("021900001")){
                                            commenBean.setValue(rowsBean.getFixValue());
                                        }else if (rowsBean.getDefaultValue().equals("021900003")){


                                            switch (rowsBean.getLoginValue()){
                                                case "userId":
                                                    commenBean.setValue(mUser.getUserId());
                                                    break;
                                                case "account":
                                                    commenBean.setValue(mUser.getUserName());
                                                    break;
                                                case "accountId":
                                                    commenBean.setValue(mUser.getUserId());
                                                    break;
                                                case "realName":
                                                    commenBean.setValue(mUser.getUserName());
                                                    break;
                                                case "organizeId":
                                                    commenBean.setValue(mUser.getCompanyId());
                                                    break;
                                                case "organizeName":
                                                    commenBean.setValue(mUser.getCompanyName());
                                                    break;
                                                case "departmentId":
                                                    commenBean.setValue(mUser.getDeptId());
                                                    break;
                                                case "departmentName":
                                                    commenBean.setValue(mUser.getDeptName());
                                                    break;
                                                case "positionId":
                                                    commenBean.setValue(mUser.getDeptId());
                                                    break;
                                                case "positionName":
                                                    commenBean.setValue(mUser.getDeptName());
                                                    break;
                                            }
                                        }
                                    }else {
                                        commenBean.setValue(custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropValue());
                                    }
                                }

                            }else {
                                commenBean.setValue(custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropValue());
                            }
                            commenBean.setConType(rowsBean.getConType());
                            commenBean.setFieldSave(rowsBean.getFieldSave());
                            commenBean.setValidate(rowsBean.getValidate());
                            commenBean.setRowLabel(rowsBean.getRowLabel());

                            mMasterCommBean.add(commenBean);
                        }
                    }
                }else {
                    SingleCheckCustom custom = (SingleCheckCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //子表
                            commenBeanUp = new CaseSaveBean.CommenBeanToUp();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmCurrentBoxBean().getDropValue())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBeanUp.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){


                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBeanUp.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBeanUp.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBeanUp.setValue(custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropValue());
                                }
                            }else {
                                commenBeanUp.setValue(custom.getmCurrentBoxBean()==null?null:custom.getmCurrentBoxBean().getDropValue());
                            }
                            commenBeanUp.setConType(rowsBean.getConType());
                            commenBeanUp.setFieldSave(rowsBean.getFieldSave());
                            childPutBean(bean.getChildName(),commenBeanUp,list);
                        }
                    }
                }

            }else if (view instanceof CheckBoxCustom){
                if (isMarstr){
                    CheckBoxCustom custom = (CheckBoxCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //主表
                            commenBean = new CaseSaveBean.CommenBean();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmCurrentValue())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBean.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){


                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBean.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBean.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBean.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBean.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBean.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBean.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBean.setValue(custom.getmCurrentValue());
                                }
                            }else {
                                commenBean.setValue(custom.getmCurrentValue());
                            }
                            commenBean.setConType(rowsBean.getConType());
                            commenBean.setFieldSave(rowsBean.getFieldSave());
                            commenBean.setValidate(rowsBean.getValidate());
                            commenBean.setRowLabel(rowsBean.getRowLabel());

                            mMasterCommBean.add(commenBean);
                        }
                    }
                }else {
                    CheckBoxCustom custom = (CheckBoxCustom) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            //子表
                            commenBeanUp = new CaseSaveBean.CommenBeanToUp();
                            if (rowsBean.getIsDefault()==1)
                            {
                                if (TextUtils.isEmpty(custom.getmCurrentValue())){
                                    if (rowsBean.getDefaultValue().equals("021900001")){
                                        commenBeanUp.setValue(rowsBean.getFixValue());
                                    }else if (rowsBean.getDefaultValue().equals("021900003")){


                                        switch (rowsBean.getLoginValue()){
                                            case "userId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "account":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "accountId":
                                                commenBeanUp.setValue(mUser.getUserId());
                                                break;
                                            case "realName":
                                                commenBeanUp.setValue(mUser.getUserName());
                                                break;
                                            case "organizeId":
                                                commenBeanUp.setValue(mUser.getCompanyId());
                                                break;
                                            case "organizeName":
                                                commenBeanUp.setValue(mUser.getCompanyName());
                                                break;
                                            case "departmentId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "departmentName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                            case "positionId":
                                                commenBeanUp.setValue(mUser.getDeptId());
                                                break;
                                            case "positionName":
                                                commenBeanUp.setValue(mUser.getDeptName());
                                                break;
                                        }
                                    }
                                }else {
                                    commenBeanUp.setValue(custom.getmCurrentValue());
                                }
                            }else {
                                commenBeanUp.setValue(custom.getmCurrentValue());
                            }
                            commenBeanUp.setConType(rowsBean.getConType());
                            commenBeanUp.setFieldSave(rowsBean.getFieldSave());
                            childPutBean(bean.getChildName(),commenBeanUp,list);
                        }
                    }
                }


            }else if (view instanceof ImagePickView){
                if (!isMarstr){
                    ImagePickView custom = (ImagePickView) view;
                    for (CaseBean.ModulesBean.RowsBean rowsBean : bean.getRows()) {
                        String index = rowsBean.getRowIndex()+"";
                        if (custom.getmRowIndex().equals(index)){
                            List<ImageItem> items = custom.getPics();
                            if (items.size()==0)return;

                            //子表
                            for (ImageItem item: items){
                                if (item.path == null)continue;
                                //多张图片上传
                                commenBeanUp = new CaseSaveBean.CommenBeanToUp();
                                if (rowsBean.getIsDefault()==1)
                                {
                                    if (custom.getPics()!=null){
                                        if (rowsBean.getDefaultValue().equals("021900001")){
                                            commenBeanUp.setValue(rowsBean.getFixValue());
                                        }else if (rowsBean.getDefaultValue().equals("021900003")){

                                            switch (rowsBean.getLoginValue()){
                                                case "userId":
                                                    commenBeanUp.setValue(mUser.getUserId());
                                                    break;
                                                case "account":
                                                    commenBeanUp.setValue(mUser.getUserName());
                                                    break;
                                                case "accountId":
                                                    commenBeanUp.setValue(mUser.getUserId());
                                                    break;
                                                case "realName":
                                                    commenBeanUp.setValue(mUser.getUserName());
                                                    break;
                                                case "organizeId":
                                                    commenBeanUp.setValue(mUser.getCompanyId());
                                                    break;
                                                case "organizeName":
                                                    commenBeanUp.setValue(mUser.getCompanyName());
                                                    break;
                                                case "departmentId":
                                                    commenBeanUp.setValue(mUser.getDeptId());
                                                    break;
                                                case "departmentName":
                                                    commenBeanUp.setValue(mUser.getDeptName());
                                                    break;
                                                case "positionId":
                                                    commenBeanUp.setValue(mUser.getDeptId());
                                                    break;
                                                case "positionName":
                                                    commenBeanUp.setValue(mUser.getDeptName());
                                                    break;
                                            }
                                        }
                                    }else {
                                        CaseSaveBean.FileInfo info = new CaseSaveBean.FileInfo();
                                        info.setName(item.name);
                                        info.setFileType(item.name.substring(item.name.length()-3,item.name.length()));
                                        info.setContent(Util.path2String(item.path));
                                        commenBeanUp.setValue(new Gson().toJson(info));
                                    }
                                }else {
                                    CaseSaveBean.FileInfo info = new CaseSaveBean.FileInfo();
                                    info.setName(item.name);
                                    info.setFileType(item.name.substring(item.name.length()-3,item.name.length()));
                                    info.setContent(Util.path2String(item.path));
                                    commenBeanUp.setValue(new Gson().toJson(info));
                                }
                                commenBeanUp.setConType(rowsBean.getConType());
                                commenBeanUp.setFieldSave(rowsBean.getFieldSave());

                                childPutBean(bean.getChildName(),commenBeanUp,list);
                            }
                        }
                    }
                }
            }
        }

    }

    private void childPutBean(String field,CaseSaveBean.CommenBeanToUp bean,List<CaseSaveBean.CommenBeanToUp> mList){
        if (TextUtils.isEmpty(bean.getValue())){
            bean.setValue("");
        }
        mList.add(bean);
    }


    private List<View> getAllChildViews(View view) {
        List<View> allchildren = new ArrayList<View>();
        if (view instanceof ViewGroup) {
            ViewGroup vp = (ViewGroup) view;
            for (int i = 0; i < vp.getChildCount(); i++) {
                View viewchild = vp.getChildAt(i);
                allchildren.add(viewchild);
                //再次 调用本身（递归）
                allchildren.addAll(getAllChildViews(viewchild));
            }
        }
        return allchildren;
    }


    public void getInfoByProType(){
        if (mCaseBean == null){
            mView.showMes("请重新进入界面");
            return;
        }
        List<Map<String,String>> mList = new ArrayList<>();
        Map<String,String> mPreType = new HashMap<>();
        for (CaseDetailBean.ModulesBean bean : mCaseBean.getModules()){
            if (bean.getModuleTitle().equals("隐藏信息")){
                for (CaseBean.ModulesBean.RowsBean mRow : bean.getRows()){
                    if (mRow.getFieldSave().equals("next_c_form_id")){
                        mPreType.put(mRow.getFieldSave(),mRow.getFixValue());
                    }
                }
            }
        }
        mList.add(mPreType);
        mView.showPb();
        Map<String,Object> params = new HashMap<>();
        params.put("preRole",mList);
        params.put("preType",mCaseBean.getId());
        Disposable disposable = RealNetWorkUtil.postContent()
                .method("api-process/lPred/getInfoByPreType")
                .content(params)
                .build().enqueueForArray(CaseType.class, new CallBackImpl<List<CaseType>>() {

                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb();
                        mView.showMes(msg);
                    }

                    @Override
                    public void onNext(List<CaseType> caseTypes) {
                        mView.hidePb();
                        if (caseTypes!=null&&caseTypes.size()>0){
                            mView.returnCaseTypeList(caseTypes);
                        }else {
                            mView.showMes("未查到流程");
                        }
                    }
                });
        mCompositeDisposable.add(disposable);
    }

    int i = 0;

    private void updateChildValue(){
        mUpdateChildCaseInfoList.clear();
        UpdateChildValueInfoBean mUpdateChildCaseInfo = null;

        i = 0;
        for (Map.Entry<String, List<List<CaseSaveBean.CommenBeanToUp>>> entry : mChildCommBean.entrySet()) {
            i++;
            String mapKey = entry.getKey();

            if (mDetailBean != null){
                for (CaseDetailBean.ModulesBean modulesBean : mDetailBean.getModules()){
                    if (mapKey.equals(modulesBean.getChildName())){
                        for (CaseDetailBean.ModulesBean.ChildValuesBean valuesBean : modulesBean.getChildValues()){
                            mUpdateChildCaseInfo = new UpdateChildValueInfoBean();
                            mUpdateChildCaseInfo.setSonTable(mapKey);
                            List<CaseSaveBean.CommenBeanToUp> list = new ArrayList<>();
                            mUpdateChildCaseInfo.setSonDatas(list);
                            for (List<CaseSaveBean.CommenBeanToUp> beanToUps : entry.getValue()){
                                mUpdateChildCaseInfo.getSonDatas().addAll(beanToUps);
                            }
                            mUpdateChildCaseInfo.setMainId(mView.getCaseid());

                            mUpdateChildCaseInfo.setId(valuesBean.getChild_id());
                            mUpdateChildCaseInfoList.add(mUpdateChildCaseInfo);
                        }
                    }
                }
            }


            commitChildValue(mUpdateChildCaseInfoList);
        }
    }

    private void commitChildValue(List<UpdateChildValueInfoBean> upBean){
        final int count = mChildCommBean.size();
        //初始化控件
        mView.showPb_mes("正在提交数据");
        Disposable disposable = RealNetWorkUtil.postContent()
                .method("api-customerform/baseFunction/viceUpdateBatch")
                .content(upBean)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        mView.showMes("保存失败");
                    }

                    @Override
                    public void onNext(String objects) {
                        mView.hidePb_mes();
                        if (count == i) {
                            mView.showMes("更新成功");
                            mView.saveSuccess(objects);
                        }else {
                            mView.showMes("更新第"+i+"个字表成功");
                        }
                    }
                });
        mCompositeDisposable.add(disposable);
    }

    @Override
    public void release() {
        super.release();
        if (mHandler != null){
            mHandler.removeCallbacksAndMessages(null);
        }
    }
}
